<?php echo $html->link(__('New Listing Type'),'/admin/listing_types/add',array('class'=>'add_button'));?>

<?php
echo "<div class='switcher'>";
echo __("Switch to ").$html->link("Field Groups",array("plugin"=>"eav","controller"=>"fieldsets","action"=>"index"));
echo "&nbsp;&nbsp;".$html->link("Listing Categories",array('plugin'=>'categories','controller'=>'categories','action'=>"index"));
echo "</div>";

if(!empty($listingTypes))
{
	$index->setData($listingTypes,'ListingType');
	$index->showFields(array('id',array('created'=>'Date Created'),'name',array('fieldset'=>'Field Group')));
	$index->sortableFields(array('id','name'));
	
	$index->setAction(__('View'), '/admin/listing_types/view/:ListingType.id');
	$index->setAction(__('Edit'), '/admin/listing_types/edit/:ListingType.id');
	$index->setAction(__('Sort Field Groups'), '/admin/listing_types/setOrders/:ListingType.id',array(),false,true,'showSortLink');
	$index->setAction(__('Delete'), '/admin/listing_types/delete/:ListingType.id',$this->helpers,__('Are you sure you want to delete this listing type ?'));
	
	$index->addColumn('fieldset','showFieldsetList');
	$index->addColumn('created','showFormatedDate');
	
	function showFormatedDate($record)
	{
		return date('Y-m-d',strtotime($record['ListingType']['created']));
	}
	
	function showFieldsetList($result)
	{
		$fieldsets = array();
		if(!empty($result['Fieldset']))
		{
			foreach($result['Fieldset'] as $fieldset)
			{
				if(!isset($fieldsets[$fieldset['entity']]))
				{
					$fieldsets[$fieldset['entity']] = array();
				}
				$fieldsets[$fieldset['entity']][] = ClassRegistry::getObject('view')->loaded['html']->link($fieldset['name'],array('controller'=>"custom_fields",'action'=>"index",'fieldset'=>$fieldset['id'])); 
			}
		}
		$out = "";
		foreach($fieldsets as $entity => $links)
		{
			$linksJoined = implode(',',$links);
			$fieldsets[$entity] = '<b>'.__($entity).'</b>: '.$linksJoined;
		}
		$out = implode('<br />',$fieldsets);
		return $out;
	}
	
	function showSortLink($result)
	{
		return count(@$result['Fieldset']) > 0;
	}
	$index->setPaginateSeparator(' ');
	echo $index->display();
}else
{
	echo "<h4>".__('No listing Types found!')."</h4>";
}
?>
